<?php

class Breadcrumbs implements ISingleton
{
	/**
	 * @var Breadcrumbs
	 */
	private static $_instance;
	
	/**
	 * Breadcrumbs parts.
	 * 
	 * @var array
	 */
	protected $_elements = array();
	
	/**
	 * @return Breadcrumbs
	 */
	private function __construct() {}
	
	/**
	 * @return Breadcrumbs
	 */
	public static function getInstance()
	{
		if (!self::$_instance) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	/**
	 * Generate Breadcrumbs from string.
	 * 
	 * @return Breadcrumbs
	 */
	public function fromString($string)
	{
		$crumbs = explode('/', $string);
		foreach ($crumbs as &$crumb) {
			$this->addCrumb($crumb);
		}
		
		return $this;
	}
	
	/**
	 * Adding Breadcrumb part.
	 * 
	 * @return void
	 */
	public function addCrumb($crumb)
	{
		$this->_elements[] = $crumb;
	}
	
	/**
	 * Render breadcrumbs.
	 * 
	 * @return string
	 */
	public function __toString()
	{
		return implode(' / ', $this->_elements);
	}
}